<template>
	<view>
		<view style="display: flex;flex-direction: row; padding: 10px 14px;">
			<view style="width: 65px;display: flex;align-items: center;">
				<span>车辆图片</span>
			</view>
			<u-upload :action="action" @on-success='uploadSuccess' @on-remove="onRemove" :file-list="fileList">
			</u-upload>
		</view>
		<u-field v-model="car.code" label="车牌号" placeholder="请填写车牌号" />
		<u-field v-model="car.type" label="类型" placeholder="请选择类型" disabled @click="showType =true" />
		<u-field v-model="car.brand" label="品牌" placeholder="请填写品牌" />
		<u-field v-model="car.seat" label="座位数" placeholder="请选择座位数" disabled @click="showSeat =true" />
		<u-field v-model="car.gear" label="变速箱" placeholder="请选择变速箱" disabled @click="showGear =true" />
		<u-field v-model="car.tank" label="油箱排量" placeholder="请填写油箱排量(单位L)" />
		<u-field v-model="car.displacement" label="排量" placeholder="请填写排量(单位T)" />
		<u-field v-model="car.remark" label="备注" placeholder="请填写备注" type="textarea" />
		<u-picker v-model="showType" mode="selector" :default-selector="[0]" :range="typeSelector"
			@confirm="comfirmType"></u-picker>
		<u-picker v-model="showSeat" mode="selector" :default-selector="[0]" :range="seatSelector"
			@confirm="comfirmSeat"></u-picker>
		<u-picker v-model="showGear" mode="selector" :default-selector="[0]" :range="gearSelector"
			@confirm="comfirmGear"></u-picker>
		<u-toast ref="uToast" />
		<u-button @click="addCar" shape="circle" :custom-style="{width:'100%',marginTop:'40rpx'}" type="primary"
			style="width: 86%;">上传车辆</u-button>
	</view>
</template>

<script>
	import SET from '@/SET.js'
	export default {
		data() {
			return {
				typeSelector: ['轿车', 'SUV', 'MPV', '跑车', '越野汽车', '皮卡'],
				seatSelector: ['1', '2', '3', '4', '5', '6'],
				gearSelector: ['液力自动', '机械无级自动', '电控机械自动', '双离合', '手动'],
				showType: false,
				showSeat: false,
				showGear: false,
				car: {
					userId: this.$store.state.userInfo.id,
					code: '',
					type: '',
					brand: '',
					seat: '',
					config: '',
					gear: '',
					tank: '',
					displacement: '',
					imgs: '',
					remark: '',
					status: '未发布'
				},
				imgs: [],
				mobile: '',
				action: SET.baseUrl + '/system/common/upload-file',
				fileList: []
			}
		},
		methods: {
			addCar() {
				this.car.imgs = this.imgs.join(",")
				this.$api.addCar(this.car).then(res => {
					this.$refs.uToast.show({
						title: res.result,
						type: 'success',
						callback() {
							uni.redirectTo({
								url: '/pages/user/car/car'
							})
						}
					})
				})
			},
			onRemove(index, lists, name) {
				console.log(index, lists, name)
			},
			uploadSuccess(e) {
				this.imgs.push(e.result.path)
				this.$refs.uToast.show({
					title: '上传成功',
					type: 'success'
				})
			},
			comfirmType(e) {
				this.car.type = this.typeSelector[e[0]]
			},
			comfirmSeat(e) {
				this.car.seat = this.seatSelector[e[0]]
			},
			comfirmGear(e) {
				this.car.gear = this.gearSelector[e[0]]
			}
		}
	}
</script>

<style>

</style>
